// mmo_game_server/communication/grpc_client.go
package communication

import (
    "context"
    "google.golang.org/grpc"
    pb "your_project/proto"
)

// GRPCClient 创建gRPC客户端
func GRPCClient(serverAddr string) (pb.LoginServiceClient, error) {
    conn, err := grpc.Dial(serverAddr, grpc.WithInsecure())
    if err != nil {
        return nil, err
    }
    client := pb.NewLoginServiceClient(conn)
    return client, nil
}

// Login 调用登录服务
func Login(client pb.LoginServiceClient, username, password string) (*pb.LoginResponse, error) {
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()
    req := &pb.LoginRequest{
        Username: username,
        Password: password,
    }
    resp, err := client.Login(ctx, req)
    if err != nil {
        return nil, err
    }
    return resp, nil
}